//
//  ViewController.m
//  08-集成通讯录(RHAddressBook)
//
//  Created by J on 16/3/1.
//  Copyright © 2016年 J. All rights reserved.
//

#import "ViewController.h"
#import <RHAddressBook/AddressBook.h>

@interface ViewController ()
@property(nonatomic,strong)RHAddressBook *ab;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    RHAddressBook *ab = [[[RHAddressBook alloc] init] autorelease];
    self.ab = ab;
    //query current status, pre iOS6 always returns Authorized
    if ([RHAddressBook authorizationStatus] == RHAuthorizationStatusNotDetermined){
        
        //判断是否授权
        [ab requestAuthorizationWithCompletion:^(bool granted, NSError *error) {

            if (granted) {
                NSLog(@"授权成功");
            }else{
                NSLog(@"授权失败");
            }
        }];
    }
    


}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    

    NSArray *allPeople = [self.ab people];
    for (RHPerson* person in allPeople) {
        NSLog(@"%@",[person.phoneNumbers valueAtIndex:0]);//获取电话号码
        
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
